package com.jrfid.smartcabinet.demo.db

import androidx.room.*
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import com.jrfid.smartcabinet.demo.App
import com.jrfid.smartcabinet.demo.db.dao.AccountInfoDao
import com.jrfid.smartcabinet.demo.db.dao.FaceInfoDao
import com.jrfid.smartcabinet.demo.db.dao.FingerInfoDao
import com.jrfid.smartcabinet.demo.db.dao.NFCInfoDao
import com.jrfid.smartcabinet.demo.db.entity.AccountInfoEntity
import com.jrfid.smartcabinet.demo.db.entity.FaceInfoEntity
import com.jrfid.smartcabinet.demo.db.entity.FingerInfoEntity
import com.jrfid.smartcabinet.demo.db.entity.NFCInfoEntity

/**
 * author: shihao
 * date: 2020/12/10 10:30
 * description:
 */
@Database(
    entities = [AccountInfoEntity::class, FingerInfoEntity::class, FaceInfoEntity::class, NFCInfoEntity::class],
    version = 1,
    exportSchema = false
)
abstract class AppDatabase : RoomDatabase() {

    companion object {
        val instance = Single.sin
    }

    private object Single {
        private val migration_1_2: Migration = object : Migration(2, 3) {
            override fun migrate(database: SupportSQLiteDatabase) {
                database.execSQL("ALTER TABLE RecordEntity ADD COLUMN readerPower Text")
            }
        }

        val sin: AppDatabase = Room.databaseBuilder(App.instance(), AppDatabase::class.java, "app.db").allowMainThreadQueries().build()
    }

    abstract fun getAccountInfoDao(): AccountInfoDao

    abstract fun getFingerInfoDao(): FingerInfoDao

    abstract fun getFaceInfoDao(): FaceInfoDao

    abstract fun getNFCInfoDao(): NFCInfoDao

}